<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>考试系统-考题添加页面</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/custom/common/css/style.css}">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script th:src="@{/bootstrap/js/html5shiv.min.js}"></script>
    <script th:src="@{/bootstrap/js/respond.min.js}"></script>
    <![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">考试系统管理</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!--<ul class="nav navbar-nav">
                <li class="active"><a href="#">考题 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">考卷</a></li>
                <li><a href="#">考试</a></li>
                <li><a href="#">设置</a></li>
            </ul>-->
            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">张三 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">修改密码</a></li>
                        <li><a href="#">修改信息</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a th:href="@{/manage/exit}">退出</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-2">
            <div class="list-group">
                <a th:href="@{/manage/index}" class="list-group-item">首页</a>
                <a th:href="@{/manage/question/list}" class="list-group-item active">考题管理</a>
                <a th:href="@{/manage/paper/list}" class="list-group-item">考卷管理</a>
                <a th:href="@{/manage/exam/list}" class="list-group-item">考试管理</a>
                <a th:href="@{/manage/user/list}" class="list-group-item">用户管理</a>
            </div>
        </div>
        <div class="col-lg-10">
            <ol class="breadcrumb">
                <li><a th:href="@{/manage/question/list}">考题管理</a></li>
                <li class="active">考题添加</li>
            </ol>
            <form>
                <div class="form-group">
                    <label for="inlineRadio1">题型：</label>
                    <label class="radio-inline">
                        <input type="radio" name="type" id="inlineRadio1" value="1" checked> 单选题
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="type" id="inlineRadio2" value="2"> 多选题
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="type" id="inlineRadio3" value="3"> 判断题
                    </label>
                </div>
                <div class="form-group">
                    <label for="content">题干：</label>
                    <textarea class="form-control" rows="5" id="content" name="content" placeholder="题干"></textarea>
                </div>
                <div class="form-group">
                    <label for="content">选项：</label>
                    <ol type="A" id="optionList">
                        <li>
                            <div class="row">
                                <div class="col-lg-8">
                                    <div class="type3 hidden">对</div>
                                    <div class="type12">
                                    <textarea class="form-control" rows="5" name="option" placeholder="选项内容"></textarea>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="answer" value="">
                                            正确答案
                                        </label>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <span class="btn btn-danger optionDelBtn">删除</span>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="row">
                                <div class="col-lg-8">
                                    <div class="type3 hidden">错</div>
                                    <div class="type12">
                                        <textarea class="form-control" rows="5" name="option" placeholder="选项内容"></textarea>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="answer" value="">
                                            正确答案
                                        </label>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <span class="btn btn-danger optionDelBtn">删除</span>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="row">
                                <div class="col-lg-8">
                                    <textarea class="form-control" rows="5" name="option" placeholder="选项内容"></textarea>
                                </div>
                                <div class="col-lg-2">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="answer" value="">
                                            正确答案
                                        </label>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <span class="btn btn-danger optionDelBtn">删除</span>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="row">
                                <div class="col-lg-8">
                                    <textarea class="form-control" rows="5" name="option" placeholder="选项内容"></textarea>
                                </div>
                                <div class="col-lg-2">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="answer" value="">
                                            正确答案
                                        </label>
                                    </div>
                                </div>
                                <div class="col-lg-2">
                                    <span class="btn btn-danger optionDelBtn">删除</span>
                                </div>
                            </div>
                        </li>
                    </ol>
                    <div class="fyl-mt8">
                        <span class="btn btn-success" id="optionAddBtn">添加选项</span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="analysis">解析：</label>
                    <textarea class="form-control" rows="5" id="analysis" name="analysis" placeholder="解析"></textarea>
                </div>
                <div class="fyl-mb20">
                    <span class="btn btn-primary">保存后继续添加</span>
                    <span class="btn btn-success">保存后返回</span>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script th:src="@{/bootstrap/js/jquery.min.js}"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
<script>
    var optionHtml = '<li><div class="row"><div class="col-lg-8"><textarea class="form-control"rows="5"name="option"placeholder="选项内容"></textarea></div><div class="col-lg-2"><div class="radio"><label><input type="radio"name="answer"value="">正确答案</label></div></div><div class="col-lg-2"><span class="btn btn-danger optionDelBtn">删除</span></div></div></li>';
    $("#optionAddBtn").click(function () {
        $("#optionList").append(optionHtml);
    })

    $("#inlineRadio1,#inlineRadio2,#inlineRadio3").click(function(){
        var type = $(this).val();
        if (type==1){
            $('[name="answer"]').attr("type","radio");
            $('[name="answer"]').parents(".checkbox").attr("class","radio");
            $("#optionList li:gt(1)").show();
            $(".type12").removeClass("hidden");
            $(".type3").addClass("hidden");
            $(".optionDelBtn,#optionAddBtn").show();
        }

        else if(type==2){
            $('[name="answer"]').attr("type","checkbox");
            $('[name="answer"]').parents(".radio").attr("class","checkbox");
            $("#optionList li:gt(1)").show();
            $(".type12").removeClass("hidden");
            $(".type3").addClass("hidden");
            $(".optionDelBtn,#optionAddBtn").show();
        }

        else if(type==3){
            $('[name="answer"]').attr("type","radio");
            $("#optionList li:gt(1)").hide();
            $(".type12").addClass("hidden");
            $(".type3").removeClass("hidden");
            $(".optionDelBtn,#optionAddBtn").hide();
        }
    })

    $(document).on("click",".optionDelBtn",function(){
        $(this).parents("li").remove();
    })

    $(document).ready(function () {
        $('[name="answer"]').click(function () {
            var i = $(this).parents("li").index() + 1;
            $(this).val(i);
        })
    })
</script>
</body>
</html>